<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>竞拍车辆产品管理</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>

<body class="iframeBody">
<div class="Wrapper">
<div class="searchArea">
    <form id="aucCarInfoSearchForm">
        <div class="fieldset1 clearFix">
        	<div class="FXBR">
	            <div class="fieldBox">
	                <div class="label">标题</div>
	                <div class="field">
	                    <input name="prdNm" id="prdNm" type="text" class="ui-textbox" value="" ligerui="width: 160">
	                </div>
	            </div>

				<div class="fieldBox">
					<div class="label">支付表号</div>
					<div class="field">
						<input name="searchPaySchNo" id="searchPaySchNo" type="text" class="ui-textbox" value="" ligerui="width: 160">
					</div>
				</div>

				<div class="fieldBox">
					<div class="label">车辆状态</div>
					<div class="field">
						<select name="searchPrdStsCd" id="searchPrdStsCd" data-value="" ligerui="width: 160">
							<option value=" " selected="selected">请选择</option>
							<c:forEach items="${PrdStsCdNmList }" var="kv">
								<option value="${kv.key }">${kv.value }</option>
							</c:forEach>
						</select>
					</div>
				</div>

				<div class="fieldBox">
					<div class="label">售出状态</div>
					<div class="field">
						<select name="searchIsSeld" id="searchIsSeld" data-value="" ligerui="width: 160">
							<option value=" " selected="selected">请选择</option>
							<c:forEach items="${IsSeldNmList }" var="kv">
								<option value="${kv.key }">${kv.value }</option>
							</c:forEach>
						</select>
					</div>
				</div>
            </div>

            <div class="clearFix"></div>
	            <div class="btnsBox formBtns notRight">
	               <span id="searchBtn" class="sq-button-round">查询</span>
	               <span id="clearBtn" class="sq-button-round">清空</span>
	               <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
	               <span id="addBtn" class="sq-button-round">新增</span>&nbsp&nbsp&nbsp
	               <span id="batchUpBtn" class="sq-button-round">批量上架</span>
	               <span id="batchDownBtn" class="sq-button-round">批量下架</span>
					<%--<sys:funcAuth resCd="exportCarInfoExcel">
						<span id="exportXlsBtn" class="sq-button sq-button-round">导出</span>
					</sys:funcAuth>--%>
	            </div>
        	</div>
        </form>
    </div>
</div>
<div id="aucCarInfoGridId" class="sq-grid"></div>
<div id="div_Up_confirm" style="display:none">
	<form id="div_Up_confirm_form">
            <div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
            	<div class="fieldBox col_100_auto">
					<div class="label">竞拍开始时间</div>
					<div class="field">
						<input name="stValidDt" id="stValidDt" type="text"  validate="{required:true}" class="ui-datepicker" ligerui="{showTime:true}" value="" >
						 <span class="requiredSymbol">*</span>
					</div>
				</div>
				<div class="fieldBox col_100_auto">
					<div class="label">竞拍结束时间</div>
					<div class="field">
						<input name="endValidDt" id="endValidDt" type="text"  validate="{required:true}" class="ui-datepicker" ligerui="{showTime:true}" value="" >
						 <span class="requiredSymbol">*</span>
					</div>
				</div>
            </div>
    </form>
</div>
<script type="text/javascript">
	var audCarInfoGrid = null;
	$(function () {
	    initForm();
		initGrid();//注意初始化要在initForm之后,因为在初始化grid的时候需要form参数
		initEvent();
	});

	//初始化事件
	function initEvent(){
		searchBtnEvent();
	    clearBtnEvent();
	    addEvent();
        exportExcelEvent();
	}

	//初始化列表
	function initGrid(){
		$("#aucCarInfoGridId").ligerGrid({
	    	url: '<%=path%>/auccar/aucCarInfo/initList.do',
	    	method : 'get',
	    	parms:getSearchParams(),
	        columns: [
	            { display: '标题', name: 'prdNm', minWidth: 250 , align:'left',
	            	render: function (rowdata, rowindex, value){
	                    var h="";
	                    h+='<a class="sq-button-hasicon" href="javascript:showDetailBtn(';
	                    h+="'"+rowdata.id+"'";
	                    h+=')">'+value+'</a>'
	                    return h;
	                },enabledSort:true},
	            { display: '支付表号', name: 'paySchNo', width: '15%', enabledSort:true},
	            { display: '车架号', name: 'vin', width: '15%', enabledSort:true},
	            /* { display: '车辆状态', name: 'prdStsCd', width: '8%', enabledSort:true}, */
	            { display: '车辆状态', name: 'prdStsCdNm', width: '8%', enabledSort:true},
	            { display: '售出状态', name: 'isSeld', width: '0', hide: true, enabledSort:true},
	            { display: '售出状态', name: 'isSeldNm', width: '8%', enabledSort:true},
	            { display: '上架时间', name: 'stValidDt', minWidth: 120 , render:renderDate, enabledSort:true},
	            { display: '下架时间', name: 'endValidDt', minWidth: 120 , render:renderDate, enabledSort:true},
	            { display: '创建时间', name: 'crtTm', minWidth: 180 , render:renderDate, enabledSort:true},
	            getGridOperColumnContent()
	        ],
	        pageSize:10,
	        root:'rows',
	        record:'total',
	        hideLoadButton : true,
	        width: '100%',
	        height:'100%',
	        heightDiff:-2,
	        checkbox:true,
	        rownumbers:true
	    });
	    audCarInfoGrid = liger.get("aucCarInfoGridId");
	    audCarInfoGrid.setHeight(100);
	}

	//隐藏掉操作列
    function getGridOperColumnContent(){
    	var data = {
                display: '操作',
                isSort: false,
                width: 150,
                align:'left',
                render: function (rowdata, rowindex, value){
                    var h="";
                    h+='<a class="sq-button-hasicon" href="javascript:modifyBtn(';
                    h+="'"+rowdata.id+"'";
                    h+=')"><i class="sqBtnIco_4"></i>修改</a>'
                    h+='<a class="sq-button-hasicon" href="javascript:showAucCarQuo(';
                    h+="'"+rowdata.id+"'";
                    h+=')"><i class="sqBtnIco_2"></i>查看</a>'
                    return h;
                }
        	 }
        	return data;
	}

  //清空按钮事件
	function clearBtnEvent(){
        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("aucCarInfoSearchForm");
        });
	}

	//初始化表单
	function initForm(){
		$("#aucCarInfoSearchForm").ligerForm();
	}

	//查询按钮事件
	function searchBtnEvent(){
		 $("#searchBtn").click(function(event) {
	         var form = new liger.get("aucCarInfoSearchForm");
	         var data = form.getData();
	         for (name in data){
	            audCarInfoGrid.setParm(name,data[name]);
	         };
	        audCarInfoGrid.reload();
	    });
	}

	function modifyBtn(id){
		$.ligerDialog.SQopen({
            width: 800,
            height:400,
            title : '修改车辆产品信息',
            urlParms:{
            	id:id
            },
            url:'<%=path%>/auccar/aucCarInfo/toAddOrModifyPage.do',
            // 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
                    text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onOk = function () {}
                        if (Dialog.onOk) {
                        	Dialog.onOk();
                        }
                    }
                }, {
                    text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
            ]
        });
	}

	function showDetailBtn(id){
		$.ligerDialog.SQopen({
            width: 800,
            height:400,
            title : '查看车辆产品信息',
            urlParms:{
            	id:id,
            	detailFlag:true
            },
            url:'<%=path%>/auccar/aucCarInfo/toAddOrModifyPage.do',
            buttons: [
                {
                text: "关闭", type: 'cancel', cls: 'l-dialog-btn-no',
                onclick: function (item, Dialog) {
                    //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                    if (Dialog.onCancel) Dialog.onCancel();
                }
            }
        ]
        });
	}


	//新增
	function addEvent(){
		//新增
        $("#addBtn").click(function(event) {
        	$.ligerDialog.SQopen({
                width: 800,
                height:400,
                title : '新增车辆产品信息',
                urlParms:{},
                url:'<%=path%>/auccar/aucCarInfo/toAddOrModifyPage.do',
                // 自定义buttons的时候 不要设置 fixButtons: true
                buttons: [{
                        text: "保存", type: 'ok', cls: 'l-dialog-btn-ok',
                        onclick: function (item, Dialog) {
                            //在子页面里绑定 frameElement.dialog.onOk = function () {}
                            if (Dialog.onOk) {
                            	Dialog.onOk();
                            }
                        }
                    }, {
                        text: "取消", type: 'cancel', cls: 'l-dialog-btn-no',
                        onclick: function (item, Dialog) {
                            //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                            if (Dialog.onCancel) Dialog.onCancel();
                        }
                    }
                ]
            });
        });
        var ligerUpForm;
        $("#batchUpBtn").click(function(event) {
        	var selectedRows = audCarInfoGrid.getSelectedRows();
    		if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }
    		var ids = "";
    		for ( var index in selectedRows) {
    		    if(selectedRows[index].isSeld == 1){
                    $.ligerDialog.SQalert({content: "已售出车辆不能上架!", SQ_type: "warning"});
    		        return;
				}
    			ids = ids + selectedRows[index].id + ",";
    		}
    		$.ligerDialog.SQopen({
                width: 450,
                top: 100,
                buttons: [
                    {
                        text: "上架", cls: 'l-dialog-btn-ok', onclick:function(){
                        	confirmUpOk(ids);
                        }
                    }
                ],
                title : '请选择竞拍时间及期限',
                target: $("#div_Up_confirm")
            });

    		ligerUpForm = $("#div_Up_confirm_form").ligerForm({
             	 validate: true
      		});
    		//清空字段值
    		resetUpForm(ligerUpForm);
        });

      //重置表单
    	function resetUpForm(ligerUpForm){
    		var form = new liger.get("div_Up_confirm_form");
			form.setData({
				stValidDt : "",
				endValidDt : ""
			});
    	}

    	function confirmUpOk(ids){
    		if (!ligerUpForm.valid()) {
                UIUtils.alertWarning(LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO);
                return false; //验证不通过，不执行以下代码
            }
    		var stValidDt = $("#stValidDt").val();
    		var endValidDt = $("#endValidDt").val();
    		$.ajax({
    			type: 'post',
    			dataType:'json',
    			data:{
    				ids:ids,
    				stValidDt:stValidDt,
    				endValidDt:endValidDt,
    				state:0
    			},
    			url: '<%=path%>/auccar/aucCarInfo/confirmBatch.do',
    			success:function(msg){
    				 if(msg.success == 1){
    					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
    					 $.ligerDialog.hide();
    					 audCarInfoGrid.reload();
    				 }else{
    					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
    				 }
    			}
    		});

    	}

    	$("#batchDownBtn").click(function(event) {
    		var selectedRows = audCarInfoGrid.getSelectedRows();
    		if (selectedRows.length == 0) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_MORE_ROW, SQ_type: "warning"});
                return;
            }

    		$.ligerDialog.confirm("确认下架吗?", function (flag) {
        		if(flag == false)return;
        		var ids = "";
        		for ( var index in selectedRows) {
        			ids = ids + selectedRows[index].id + ",";
        		}
        		$.ajax({
        			type: 'post',
        			dataType:'json',
        			data:{
        				ids:ids,
        				state:1
        			},
        			url: '<%=path%>/auccar/aucCarInfo/confirmBatch.do',
        			success:function(msg){
        				 if(msg.success == 1){
        					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
        					 $.ligerDialog.hide();
        					 audCarInfoGrid.reload();
        				 }else{
        					 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
        				 }
        			}
        		});
        	});
    	});
	}

	//查询参数
	function getSearchParams(){
		var form = new liger.get("aucCarInfoSearchForm");
        var data = form.getData();
        return data;
	}

	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
		}
		return dateStr;
	}

	//格式化时间
	function renderDateNew(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}

	//查看竞拍结果
	function showAucCarQuo(id){
		var callback = function(){
			 grid.reload();
		}
		var detailFlag = true;
		Add_navTab('showAucCarQuo'+id,'查看竞拍结果','<%=path%>/auccar/aucCarQuo/toListPage.do?id='+id+'&detailFlag='+detailFlag,callback);
	}

	function clearBtn(){
		var form = new liger.get("aucCarInfoSearchForm");
		form.clear();
	}

	function iframeResize () {
	    if (parent.mainApp) {
	        parent.mainApp.parentTab.onResize();
	    };
	}


    //导出信息
    function exportExcelEvent(){
		$("#exportXlsBtn").click(function (event) {
			var form = liger.get("aucCarInfoSearchForm");
			var data = form.getData();
			var wait_dialog;
			$.ajax({
				type: 'post',
				dataType:'json',
				url: '<%=path%>/auccar/aucCarInfo/exportCarInfoExcel.do',
				data:data,
				beforeSend:function(){
					wait_dialog=$.ligerDialog.SQalert({content: '正在导出...',SQ_type: "waitting"});
				},
				success:function(msg){
					wait_dialog.close();
					if(msg.success == 1){
						window.open(msg.data);
					}else{
						$.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
					}
				}
			});
		});
    }
</script>

</body>
</html>
